import { axios } from "@/services/axios";
import {useEffect, useMemo, useState} from "react";

const Workflow = {
  check: data => axios.post(`api/workflow/check`,data),
  edit: data => axios.get(`api/workflow/edit/${data.bill}/${data.billtype}/${data.billid}/${data.userid}`),
  getmessage: data => axios.get(`api/workflow/message/${data.bill}/${data.billid}/${data.bill_type}/${data.orgunitid}`),
  getlist: params => axios.post(`api/workflow/list`, params),
  get: data => axios.get(`api/workflow/${data.id}`),
  create: data => axios.post("api/workflow", data),
  getid: data => axios.get("api/workflow", data),
  save: data => axios.post(`api/workflow/${data.id}`, data),
  delete: data => axios.post(`api/workflow/delete/${data.id}`),
  copy: data => axios.post(`api/workflow/copy/${data.id}/${data.userid}`),
  getchecklist: params => axios.post(`api/workflow/checkList`, params),
  getcheckmessag: params => axios.post(`api/workflow/checkmessag`, params),
  checkuser: data => axios.post(`api/workflow/user`,data),
};

export function useWorkflowUser(billdata) {
  const [workflowUserLoaded, setworkflowUserLoaded] = useState(false);
  const [workflowUserdata, setworkflowUserdata] = useState([]);

  useEffect(() => {
    let cancelDataSourceLoading = false;
    Workflow.checkuser(billdata).then(data => {
      if (!cancelDataSourceLoading) {
        setworkflowUserLoaded(true);
        setworkflowUserdata(data);
    }});

    return () => {
      cancelDataSourceLoading = true;
    };
  }, [billdata]);

  return useMemo(() => ({ workflowUserLoaded, workflowUserdata }), [workflowUserLoaded, workflowUserdata]);
}
export default Workflow;


